package bookshopSM;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import sale.Bestseller;
import sale.SaleBook;
import sale.ViewSaleList;
import worker.AddWorker;
import worker.UpdateCode;
import worker.UpdatePersonal;
import VIP.AddVIP;
import VIP.UpdateVIP;
import book.AddBook;
import book.BookInstock;
import book.SelectBook;

public class FrameWorker extends JFrame implements ActionListener{
    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenu1 = new JMenu("图书管理");
    JMenuItem jMenuItem11 = new JMenuItem("销售图书");
    JMenuItem jMenuItem12 = new JMenuItem("图书查询");
    JMenuItem jMenuItem13 = new JMenuItem("查看畅销书单");
    //JMenuItem jMenuItem13 = new JMenuItem("查看畅销书单");
    JMenu jMenu2 = new JMenu("会员管理");
    JMenuItem jMenuItem21 = new JMenuItem("添加新会员");
    JMenuItem jMenuItem22 = new JMenuItem("修改会员信息");
    JMenu jMenu3 = new JMenu("个人信息管理");
    JMenuItem jMenuItem31 = new JMenuItem("修改个人信息");
    JMenuItem jMenuItem32 = new JMenuItem("修改密码");
    public FrameWorker()
    {
        this.setSize(900, 700);
        // 获取屏幕尺寸
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        //获取主界面的窗体尺寸
        Dimension frameSize = this.getSize();
        this.setLocation((screenSize.width - frameSize.width) /2,
                (screenSize.height - frameSize.height) / 2);//居中显示

        JPanel contentPane = (JPanel) getContentPane();
        contentPane.setLayout( new BorderLayout() );
        setTitle("书店销售管理系统");
        setJMenuBar(jMenuBar1);
        jMenuBar1.add(jMenu1);
        jMenuBar1.add(jMenu2);
        jMenuBar1.add(jMenu3);
        jMenu1.add(jMenuItem11);
        jMenu1.add(jMenuItem12);
        jMenu1.add(jMenuItem13);
        jMenu2.add(jMenuItem21);
        jMenu2.add(jMenuItem22);
        jMenu3.add(jMenuItem31);
        jMenu3.add(jMenuItem32);

        jMenuItem11.addActionListener(this);
        jMenuItem12.addActionListener(this);
        jMenuItem13.addActionListener(this);
        jMenuItem21.addActionListener(this);
        jMenuItem22.addActionListener(this);
        jMenuItem31.addActionListener(this);
        jMenuItem32.addActionListener(this);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        //查看销售列表 查看销售额 添加新图书 图书入库 添加新员工 修改员工信息 删除员工信息
        //会员设置 添加新会员 修改会员信息 删除会员信息
        //销售图书
        if (e.getSource() == jMenuItem11)
        {  // 创建添加学生面板对象
            SaleBook VSL = new SaleBook();
            // 移除主界面上原有的内容
            this.remove(this.getContentPane());
            // 令界面可见
            this.setContentPane(VSL);
            this.setVisible(true);
        }
        //图书查询
        if (e.getSource() == jMenuItem12){
            SelectBook AB = new SelectBook();
            this.remove(this.getContentPane());
            this.setContentPane(AB);
            this.setVisible(true);
        }
        //查看畅销书单
        if (e.getSource() == jMenuItem13){
            Bestseller AB = new Bestseller();
            this.remove(this.getContentPane());
            this.setContentPane(AB);
            this.setVisible(true);
        }
        //添加新会员
        if (e.getSource() == jMenuItem21){
            AddVIP VSM = new AddVIP();
            this.remove(this.getContentPane());
            this.setContentPane(VSM);
            this.setVisible(true);
        }

        //修改会员信息
        if (e.getSource() == jMenuItem22){
            UpdateVIP BI = null;
            try {
                BI = new UpdateVIP();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(BI);
            this.setVisible(true);
        }

        //修改个人信息
        if (e.getSource() == jMenuItem31){
            UpdatePersonal AW = null;
            try {
                AW = new UpdatePersonal();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(AW);
            this.setVisible(true);
        }
        //修改密码
        if (e.getSource() == jMenuItem32){
            UpdateCode AW = null;
            AW = new UpdateCode();
            this.remove(this.getContentPane());
            this.setContentPane(AW);
            this.setVisible(true);
        }
    }

}

